package com.doit.demo01;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingDeque;

@SuppressWarnings("all")
public class test01 {
    public static void main(String[] args) {
//        BlockingQueue<Integer> integers = new ArrayBlockingQueue<>(5);
        BlockingQueue<Integer> integers = new LinkedBlockingDeque<>();
        new Thread(new Runnable() {
            @Override
            public void run() {
                while (true)
                {
                    try {
                        Thread.sleep(1000);
                        System.out.println("取出数据-->"+integers.take());
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                }
            }
        }).start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 20; i++) {
                    try {
                        integers.put(i);
                        System.out.println("存入数据-->"+i);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                }
            }
        }).start();
    }
}
